use poem_openapi::Object;
use rbatis::{crud, impl_select, impl_select_page};
use serde::{Serialize, Deserialize};

// task list table
#[derive(Debug, Clone, Default, Serialize, Deserialize, Object)]
pub struct TaskList {
    // 主键id
    pub id: Option<i64>,
    // 标题
    pub title: Option<String>,
    // 描述
    pub description: Option<String>,
    // 是否完成
    pub done: Option<bool>,
    // 创建时间
    pub created_at: Option<i64>,
    // 更新时间
    pub updated_at: Option<i64>,
}

crud!(TaskList {}); //crud = insert+select_by_column+update_by_column+delete_by_column

impl_select!(TaskList{select_by_id(id:&i64) -> Option => "`where id = #{id} limit 1`"});
impl_select_page!(TaskList{select_page() =>"
     if !sql.contains('count(1)'):
       `order by created_at desc`"});
impl_select_page!(TaskList{select_page_by_title(title:&str) =>"
     if title != null && title != '':
       `WHERE title LIKE CONCAT('%', #{title}, '%')`"});
